<template>
  <div class="main">
    <div class="graphic-course-wrapper">
      <!-- <div class="back-wrapper"> -->
      <div v-show="showBackArrow" class="back-wrapper whi flex-h">
        <div class="backboxs" @click="$router.back()">       
          <i class="imgIcon backimgs"></i>
          <span class="back">返回</span>
        </div>
        <div class="flex1"></div>
        <div class="backboxs right" @click="openShare">
          <img class="imgIcon" src="~/static/images/shareBlack.png" alt />
        </div>
      </div>
      <!-- </div> -->
      <scroller>
        <div class="course-box">
          <div v-show="showBackArrow" style="height:0.8rem"></div>
          <div class="header flex-h" v-show="titleData.commodityName">
            <div class="flex1">
              <span class="spn1">
                <b>{{titleData.commodityName}}</b>
              </span>
              <span class="spn2">
                <b>{{titleData.teacherName}}</b>
              </span>
            </div>
            <div v-if="lessonsVOListLength>1" class="right" @click="show9=true">
              <b></b>
              <img class="mulu" src="~@/static/images/activity.png" alt />
              <span>共3节</span>
            </div>
          </div>
          <div v-html="courseContent" class="vHtml" id="vHtml"></div>
        </div>
      </scroller>
    </div>
    <div v-transfer-dom>
      <popup v-model="show9" position="right">
        <div class="popup-box" style="width:6rem;">
          <h4>课程列表</h4>
          <span
            :class="['titles',switchIndex==index?'colorActive':'']"
            v-for="(its,index) in lessonsVOList"
            :key="its.id"
            @click="switchCourse(index)"
          >{{index+1}} . {{its.lessonTopic}}</span>
        </div>
      </popup>
    </div>
  </div>
</template>

<script>
import { info } from "~/api/identity";
import ls from "store2";
import { format } from "~/plugins/filter";
import { TransferDom, Popup } from "vux";
import wxapi from "~/plugins/wxapi.js";
import { showShare } from "~/components/share/index";
export default {
  // head: {
  //   title: "详情"
  // },
  directives: {
    TransferDom
  },
  components: {
    Popup
  },
  data() {
    return {
      showBackArrow: true,
      show9: false,
      titleData: {},
      lessonsVOList: [],
      lessonsVOListLength: 1,
      courseContent: "",
      switchIndex: 0
    };
  },
  created() {
    if (this.commonJs.GetUrlParam("isVip")) {
      window.location.replace(process.env.workUrl + "/wx-yxk/#/home");
      return false;
    }
    if (this.commonJs.GetUrlParam("shareArticle") || this.commonJs.GetUrlParam('mini_token')) {
      this.showBackArrow = false;
    }
  },
  mounted: function() {
    this.$visit("ArticleCourse/"+this.commonJs.GetUrlParam("type"))
    wxapi.wxRegister();
    this.info();
  },
  destroyed() {},
  methods: {
    wxShare(pic, titles, descs, id) {
      let uri;
      if (this.$store.state.vipShare) {
        uri = window.location.href + "&shareArticle=" + true + "&isVip=vip";
      } else {
        uri = window.location.href + "&shareArticle=" + true;
      }
      let option = {
        title: titles,
        desc: descs,
        link: uri,
        imgUrl: pic
      };

      wxapi.ShareAppMessage(option);
      wxapi.ShareTimeline(option);
    },
    openShare() {
      if (this.$store.state.vipShare) {
        this.$vux.toast.text("亲,专属课程禁止分享~");
        return false;
      }
      showShare("open");
    },
    info() {
      this.$loading('open');
      let obj = {
        id: this.$route.query.type
      };
      info(obj)
        .then(res => {
          let datas = res.data.commodityInfoByCidVO;
          this.titleData = datas;
          this.lessonsVOList = res.data.lessonsVOList;
          this.lessonsVOListLength = this.lessonsVOList.length;
          this.courseContent = this.lessonsVOList[0].content;
          let shareData = this.lessonsVOList[0];
          let contente = shareData.content;
          let sharedesc = contente
            .replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi, "")
            .replace(/<[^>]+?>/g, "")
            .replace(/\s+/g, " ")
            .replace(/ /g, " ")
            .replace(/>/g, " ");
          sharedesc = sharedesc.substring(0, 100) + "...";
          this.wxShare(datas.pics[0], shareData.lessonTopic, sharedesc);
          this.$hideLoading();
        })
        .catch(err => {
          this.$hideLoading();
        });
    },
    switchCourse(index) {
      this.switchIndex = index;
      this.courseContent = this.lessonsVOList[index].content;
      let shareData = this.lessonsVOList[index];
      let contente = shareData.content;
      let sharedesc = contente
        .replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi, "")
        .replace(/<[^>]+?>/g, "")
        .replace(/\s+/g, " ")
        .replace(/ /g, " ")
        .replace(/>/g, " ");
      sharedesc = sharedesc.substring(0, 100) + "...";
      this.wxShare(this.titleData.pics[0], shareData.lessonTopic, sharedesc);

      this.show9 = false;
    }
  }
};
</script>

<style scoped lang="less">
.back-wrapper {
  width: 7.5rem;
  height: 0.8rem;
  line-height: 0.8rem;
  padding: 0 0.3rem;
  box-sizing: border-box;
  position: relative;
  z-index: 10;
  background: #fff;

  .backboxs {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 1.2rem;
    height: 0.8rem;
    padding: 0.2rem 0;
  }

  .imgIcon {
    width: 0.4rem;
    height: 0.4rem;
  }
   .backimgs{
    display:inline-block;
    background: url('~@/static/sprite/icon_sprites_40.png') -0.1rem -0.1rem;
		background-size:3rem 2.4rem; 
   }
  .back {
    display: inline-block;
    margin-left: 0.1rem;
    font-weight: bold;
    color: #222;
  }
  .right {
    text-align: right;
    .imgIcon {
      margin-left: 0.8rem;
    }
  }
}

.graphic-course-wrapper {
  width: 7.5rem;
  height: 100vh;
  background: #fff;
}
.course-box {
  width: 7.5rem;
  height: auto;
  background: #fff;
  padding: 0 0.3rem;
  box-sizing: border-box;
  #vHtml {
    /deep/ img {
      width: 100%;
      height: auto;
    }
  }
}
.header {
  width: 100%;
  height: auto;
  padding-bottom: 0.3rem;
  border-bottom: 0.01rem solid rgba(229, 232, 237, 1);
  margin-bottom: 0.1rem;
  align-items: stretch;
  margin-top: 0.2rem;
  b,
  i {
    font-style: normal;
    font-weight: 500;
  }

  .spn1 {
    // height: 1.4rem;
    // padding: 0.3rem 0;
    display: block;
    width: 100%;
    box-sizing: border-box;

    b {
      font-size: 0.4rem;
      font-family: PingFangSC-Semibold, PingFangSC;
      font-weight: 600;
      color: rgba(34, 34, 34, 1);
      line-height: 0.6rem;
    }
  }

  .spn2 {
    height: 0.5rem;
    line-height: 0.5rem;
    overflow: hidden;
    margin-top: 0.3rem;

    b,
    i {
      font-size: 0.28rem;
      color: #b7b7b7;
    }

    .right {
      text-align: right;
    }
    img {
      display: inline-block;
      width: 0.4rem;
      height: 0.4rem;
      vertical-align: middle;
    }
    i {
      vertical-align: middle;
      margin-left: 0.1rem;
    }
  }
  .right {
    width: 1.2rem;
    margin-left: 0.2rem;
    position: relative;
    b {
      position: absolute;
      width: 1px;
      height: 0.6rem;
      left: 0;
      top: 0.1rem;
      background: #b7b7b7;
    }
    .mulu {
      width: 0.4rem;
      height: 0.4rem;
      display: block;
      margin: 0 auto;
    }
    span {
      height: 0.4rem;
      line-height: 0.4rem;
      display: block;
      font-size: 0.22rem;
      color: #222;
      text-align: center;
    }
  }
}
.popup-box {
  padding-left: 0.2rem;

  box-sizing: border-box;
  background: #fff;
  min-height: 100vh;
  h4 {
    display: block;
    height: 0.88rem;
    line-height: 0.88rem;
    font-size: 0.36rem;
    color: #b7b7b7;
    font-weight: 500;
  }
  span {
    display: block;
    font-size: 0.3rem;
    color: #222;
    margin-bottom: 0.2rem;
  }
  .colorActive {
    color: @mainColor;
  }
}
</style>
